﻿<template>
  <a-modal
    title="新增库位信息"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入编码" v-decorator="['placecode', {rules: [{required: true, message: '请输入编码！'}]}]" />
        </a-form-item>
        <a-form-item label="所在库区" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-select style="width: 100%" placeholder="请选择所在库区" v-decorator="['areaid', {rules: [{ required: true, message: '请选择所在库区！' }]}]">
            <a-select-option v-for="(item,index) in WmsAreaData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="排" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入排" style="width: 100%" v-decorator="['rowno', {rules: [{ required: true, message: '请输入排！' }]}]" :min="0"/>
        </a-form-item>
        <a-form-item label="列" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入列" style="width: 100%" v-decorator="['columnno', {rules: [{ required: true, message: '请输入列！' }]}]" :min="0"/>
        </a-form-item>
        <a-form-item label="层" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入层" style="width: 100%" v-decorator="['layerno', {rules: [{ required: true, message: '请输入层！' }]}]" :min="0"/>
        </a-form-item>
        <a-form-item label="巷道" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入巷道" style="width: 100%" v-decorator="['aisle', {rules: [{ required: true, message: '请输入巷道！' }]}]" :min="0"/>
        </a-form-item>
        <a-form-item label="进深号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入进深号" style="width: 100%" v-decorator="['deepcellno']" :min="0"/>
        </a-form-item>

        <a-form-item label="线号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入线号" style="width: 100%" v-decorator="['line']" :min="0"/>
        </a-form-item>
        <a-form-item label="堆垛机内部位置" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入堆垛机内部位置" v-decorator="['positionnoForSrm']" />
        </a-form-item>
        <a-form-item label="库位X坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位X坐标" style="width: 100%" v-decorator="['xzb']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位Y坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位Y坐标" style="width: 100%" v-decorator="['yzb']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位Z坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位Z坐标" style="width: 100%" v-decorator="['zzb']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位长度" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位长度" style="width: 100%" v-decorator="['length']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位宽度" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位宽度" style="width: 100%" v-decorator="['width']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位高度" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入库位高度" style="width: 100%" v-decorator="['height']" :min="0"/>
        </a-form-item>
        <a-form-item label="最大承重" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入最大承重" style="width: 100%" v-decorator="['maxweight']" :min="0"/>
        </a-form-item>
        <a-form-item label="库位高度级别" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-select style="width: 100%" placeholder="请选择库位高度级别" v-decorator="['heightlevel']">
            <a-select-option v-for="(item,index) in heightlevelData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="优先级" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入优先级" style="width: 100%" v-decorator="['priority']" :min="0"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    WmsPlaceFkWmsAreaList,
    WmsPlaceAdd
  } from '@/api/modular/main/WmsPlaceManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        WmsAreaData: [],
        visible: false,
        confirmLoading: false,
        heightlevelData: [],
        form: this.$form.createForm(this)
      }
    },
    methods: {
      WmsPlaceFkWmsAreaList() {
          WmsPlaceFkWmsAreaList().then(res => {
            this.WmsAreaData = res.data
          })
      },
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {

        })
        const placestatusOption = this.$options
        this.placestatusData = placestatusOption.filters['dictData']('place_status')
        const islockOption = this.$options
        this.islockData = islockOption.filters['dictData']('yes_or_no')
        const isfullOption = this.$options
        this.isfullData = isfullOption.filters['dictData']('yes_or_no')
        const hastaskdoingOption = this.$options
        this.hastaskdoingData = hastaskdoingOption.filters['dictData']('yes_or_no')
        const heightlevelOption = this.$options
        this.heightlevelData = heightlevelOption.filters['dictData']('height_level')
        this.WmsPlaceFkWmsAreaList()
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
				if (values[key] == null) {
						values[key] = 0
				}
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            WmsPlaceAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
